import Living

from lib import log

import random

IDLE_DUDLEY_STATE = 0

class Dudley(Living.Living):
	def __init__(self, location, world):
		super(Dudley, self).__init__('Dudley', 'A living, breathing person', location, world)
		self._state = IDLE_DUDLEY_STATE
	def comeAlive(self):
		if self._location:
			self.notify("Someone appears spontaneously!")
			self.say("Hi! My name is {0}.".format(self.name))
	def heartbeat(self):
		# do something random to demonstrate how characters can interact
		# with the world.
		if self._state == IDLE_DUDLEY_STATE:
			r = random.random()
			if r <= 0.05:
				self.notify("{0} hums.".format(self.name))
			elif r <= 0.07:
				self.notify("{0} ponders his existence momentarily and then loses focus.".format(self.name))
			elif r >= 0.98:
				self.notify("{0} checks his fingernails for dirt.".format(self.name))
		else:
			log.warn("{0} is in an unknown state.".format(self.name))
			self.notify("{0} has no idea what to do next.".format(self.name))
	def die(self):
		self.notify("Lightning flashes across the sky. 'Argghh...' {0} dies.".format(self.name))
